<?php
session_start();
if(session_is_registered($_GET["user_id"])){}
else 
die("<a href='../index.php'>PLEASE LOGIN AGAIN... </a>");
$user_id = $_GET["user_id"];
?>
<script type="text/javascript" src="../lib/dftree.js"></script>
<link rel="stylesheet" type="text/css" href="../css/myCss.css" />
<link rel="stylesheet" type="text/css" href="../css/dftree.css">

<script language="javascript">
tree = new dFTree({name: 'tree',useIcons:true, icondir:'img'});
tree.add(new dNode({id: '0',caption: 'Catalogues', url: 'http://dftree.sourceforge.net/'}),-1); //root node

<?php
include("../connect.php");
if(!(isset($_GET["user_id"])))
	$user_id = 6;
else 
	$user_id = $_GET["user_id"];

	
get_folders_root($user_id);

function get_folders_root($uid){
$query = "select * from articles where id_user_fkn = $uid";
$res = mysql_query($query);
$count = mysql_num_rows($res);
for($i=0; $i<$count; $i++)
{
	$row = mysql_fetch_object($res);
	$folder_id = $row->id_article;
	$parent_id = $row->id_parent;
	$is_folder = $row->is_folder;
	$caption   = $row->name;
	$url       = $row->path;
	$link_folder = ($is_folder == 1)?"<a href=\"tree/add_folder.php?folder_id=".$folder_id."&user_id=".$uid."\"> <img src=\"tree/img/new_folder.jpg\" width=15px> </a> &nbsp;<a href=\"tree/add_file.php?folder_id=$folder_id&user_id=$uid\"><img src=\"tree/img/new_file.jpg\" width=15px></a> &nbsp; <a href=\"tree/delete.php?id=$folder_id&user_id=$uid&type=folder\"> <img src=\"tree/img/delete.jpg\" width=15px> </a>":"<a href=\"tree/delete.php?id=$folder_id&type=file&user_id=$uid\"> <img src=\"tree/img/delete.jpg\" width=15px></a>";
	echo "tree.add(new dNode({id: '$folder_id',caption: '$caption $link_folder', isFolder:$is_folder, url: '$url'}), $parent_id);";
}
}
?>



tree.draw();
</script>
